[ACM] Don't use uninitialised struct value if hypercall fails.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Mon, 23 Oct 2006 08:57:24 +0000 (09:57 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Mon, 23 Oct 2006 08:57:24 +0000 (09:57 +0100)
From: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
tools/python/xen/lowlevel/acm/acm.c

index ec39b60bb41a073bcf2c9e460e867d62b2ef6bbf..930c568212048f5b57e1dd86a3a53c9640adb395 100644 (file)
@@ -147,9 +147,10 @@ static PyObject *getdecision(PyObject * self, PyObject * args)
 {
     char *arg1_name, *arg1, *arg2_name, *arg2, *decision = NULL;
     struct acm_getdecision getdecision;
-    int xc_handle;
+    int xc_handle, rc;
 
-    if (!PyArg_ParseTuple(args, "ssss", &arg1_name, &arg1, &arg2_name, &arg2)) {
+    if (!PyArg_ParseTuple(args, "ssss", &arg1_name,
+                          &arg1, &arg2_name, &arg2)) {
         return NULL;
     }
 
@@ -179,13 +180,17 @@ static PyObject *getdecision(PyObject * self, PyObject * args)
         getdecision.id2.ssidref = atol(arg2);
     }
 
-    if (xc_acm_op(xc_handle, ACMOP_getdecision, &getdecision, sizeof(getdecision)) < 0) {
+    rc = xc_acm_op(xc_handle, ACMOP_getdecision,
+                   &getdecision, sizeof(getdecision));
+
+    xc_interface_close(xc_handle);
+
+    if (rc < 0) {
         if (errno == EACCES)
             PERROR("ACM operation failed.");
+        return NULL;
     }
 
-    xc_interface_close(xc_handle);
-
     if (getdecision.acm_decision == ACM_ACCESS_PERMITTED)
         decision = "PERMITTED";
     else if (getdecision.acm_decision == ACM_ACCESS_DENIED)